/*
 * Copyright (c) 2008, Takashi Ito
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the authors nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _UPNP_TREE_ITEM_DATA_H_
#define _UPNP_TREE_ITEM_DATA_H_

#include "tansu_internal.h"
#include <wx/wx.h>
#include <wx/image.h>
#include <wx/treectrl.h>

#include "tansu_util.h"
#include "tansu_socket.h"
#include "tansu_ssdp.h"
#include "tansu_http.h"
#include "tansu_upnp.h"
#include "tansu_upnp_cp.h"

enum UpnpTreeItemType {
    TREE_NODE_DEVICE_TYPE,
    TREE_NODE_DEVICE,
    TREE_NODE_SERVICE,
};

class UpnpTreeItemData : public wxTreeItemData {
public:
    UpnpTreeItemData(UpnpTreeItemType type) : m_type(type) {}
    virtual ~UpnpTreeItemData() {}
    virtual UpnpTreeItemType GetNodeType() const { return m_type; }
protected:
    UpnpTreeItemType m_type;
};

class DeviceTreeItemData : public UpnpTreeItemData {

public:

    DeviceTreeItemData(struct tansu_cp_device *device)
        : UpnpTreeItemData(TREE_NODE_DEVICE)
        , device(device)
    {}

    virtual ~DeviceTreeItemData() { tansu_cp_device_delete(device); }

    const struct tansu_cp_device *GetDevice() const { return device; }

private:

    struct tansu_cp_device *device;

};

class ServiceTreeItemData : public UpnpTreeItemData {

public:

    ServiceTreeItemData(struct tansu_cp_service *service = NULL)
        : UpnpTreeItemData(TREE_NODE_SERVICE)
        , m_service(service)
    {}

    virtual ~ServiceTreeItemData() { tansu_cp_service_delete(m_service); }

    void *SetService(struct tansu_cp_service *service) {
        tansu_cp_service_delete(m_service);
        m_service = service;
    }

    const struct tansu_cp_service *GetService() const { return m_service; }

private:

    struct tansu_cp_service *m_service;

};

class TextTreeItemData : public UpnpTreeItemData {

public:

    TextTreeItemData(const wxString& text)
        : UpnpTreeItemData(TREE_NODE_DEVICE_TYPE)
        , m_text(text)
    {}

    wxString& SetText(const wxString& text) { return (m_text = text); }

    const wxString& GetText() const { return m_text; }

private:

    wxString m_text;

};

#endif // _UPNP_TREE_ITEM_DATA_H_

